package com.tt.lcd.qunyangGPRS.entity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class JinSiData {
	private String zhanID;
	private String pigID;
	private int jinsi,jihua;
	private Date date;

	public JinSiData(byte[] b,String zhanID) {
		this.zhanID = zhanID;
//		31 35 36 30 30 30 32 30 31 33 30 39 33 38 39 耳标  15
//
//		1   保留
//
//		0 0  进食量
//
//		9 60    计划
//
//
//		7 e1 2 1c    2017 2 28
		//耳标
		byte[] pid = new byte[15];
		for (int i = 0; i < pid.length; i++) {
			pid[i] = b[i];
		}
		this.pigID = new String(pid);

		//进食量


		this.jinsi = (this.getInt(b[16])<<8)+this.getInt(b[17]);
		//计划量

		this.jihua = (this.getInt(b[18])<<8)+this.getInt(b[19]);
		//时间
		int nian = (this.getInt(b[20])<<8) +this.getInt(b[21]);

		int yue = this.getInt(b[22]);

		int ri  = this.getInt(b[23]);

		SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd");
		String da = "" + nian + "-"+yue+"-"+ri;
		try {
			this.date = sdf.parse(da);

			Calendar date = Calendar.getInstance();
			date.setTime(this.date);
			date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);
			this.date = sdf.parse(sdf.format(date.getTime()));
		} catch (ParseException e) {
			e.printStackTrace();
		}


	}
	//byte转int
	public int getInt(byte i){
		int g1 = i&127;
		if(i<0){
			g1=g1+128;
		}
		return g1;
	}

	public String getPigID() {
		return pigID;
	}

	public void setPigID(String pigID) {
		this.pigID = pigID;
	}

	public String getZhanID() {
		return zhanID;
	}

	public void setZhanID(String zhanID) {
		this.zhanID = zhanID;
	}

	public int getJinsi() {
		return jinsi;
	}

	public void setJinsi(int jinsi) {
		this.jinsi = jinsi;
	}

	public int getJihua() {
		return jihua;
	}

	public void setJihua(int jihua) {
		this.jihua = jihua;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

}
